
import { Directive, ElementRef, Renderer2, Input, HostBinding } from '@angular/core';

// interface ClassConfig {
//   className?: string;
//   active?: boolean;
// }

  // @Input('appbuttondynamicclass2')
  // set appDynamicClassConfig(config: ClassConfig) {
  //   if (config.className !== undefined) {
  //     this._className = config.className;
  //   }
  //   if (config.active !== undefined) {
  //     this._active = config.active;
  //   }
  //   this.updateClass();
  // }

  // private _className: string | undefined;
  // private _active: boolean | undefined;

  // constructor(private el: ElementRef, private renderer: Renderer2) {}

  // private updateClass() {
  //   if (this._className && this._active !== undefined) {
  //     this.renderer[this._active ? 'addClass' : 'removeClass'](this.el.nativeElement, this._className);
  //   }
  // }

@Directive({
  selector: '[appbuttondynamicclass2]'
})

export class ButtonDynamicClass2Directive {


  constructor(private element:ElementRef,private render :Renderer2){

  }

  @HostBinding("class")
   customClass:string="";

  @Input('appbuttondynamicclass2')
  set setClass(value:Object){
    let items= Object.entries(value);
    for (let item of items){
        const [className,condition]=item;
        if(className && condition===true ){
          // this.render.addClass(this.element.nativeElement,className);
          this.customClass=(this.customClass+" "+ className).trim();
        }
    }
  }
}